<template>
  <div>
    <div>
      <v-viewer ref="view"></v-viewer>
      <el-form size="medium">
        <el-form :inline="true">
          <el-form-item label="时间">
            <el-date-picker v-model="dateRange"
                            type="daterange"
                            range-separator="~"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            format="yyyy 年 MM 月 dd 日"
                            value-format="yyyy-MM-dd">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="客户名称">
            <el-input v-model="customerName"
                      placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item label="客户手机号">
            <el-input v-model.number="customerPhone"
                      placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item size="large">
            <el-button type="primary"
                       v-if="buttonAuthority.some(a => a==='newOrder')"
                       @click="newOrder">新增订单</el-button>
          </el-form-item>
        </el-form>
        <el-form :inline="true">
          <el-form-item label="尾款状态">
            <el-select v-model="finalCostStatus"
                       placeholder="请选择">
              <el-option label="已结清"
                         value=1>
              </el-option>
              <el-option label="未结清"
                         value=0>
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="订单状态">
            <el-select v-model="orderStatus">
              <el-option label="下单中"
                         value="2"></el-option>
              <el-option label="订单审核未通过"
                         value="3"></el-option>
              <el-option label="已打款"
                         value="4"></el-option>
              <el-option label="货好"
                         value="11"></el-option>
              <el-option label="运输中"
                         value="5"></el-option>
              <el-option label="已入库"
                         value="6"></el-option>
              <el-option label="售后待审核"
                         value="7"></el-option>
              <el-option label="可配送"
                         value="9"></el-option>
              <el-option label="完成"
                         value="10"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary"
                       @click="getOrderList">查询</el-button>
            <el-button type="primary"
                       @click="reset">重置</el-button>
          </el-form-item>
        </el-form>
      </el-form>
      <template>
        <el-table ref="orderTable"
                  border
                  :row-class-name="statusColor"
                  :data="orderList"
                  :expand-row-keys="nowOpen"
                  row-key="id"
                  style="width: 100%">
          <el-table-column type="expand">
            <template slot-scope="props">
              <el-table border
                        :row-class-name="statusColor"
                        :data="props.row.item"
                        style="width: 100%">
                <template v-for='(col) in childOrderHeader'>
                  <el-table-column :show-overflow-tooltip="true"
                                   :label="col.value"
                                   :key="col.key">
                    <template slot-scope="scope">
                      <template v-if="col.key === 'official_picture'">
                        <pic-view :file-list="scope.row.officialUrlList"
                                  upload-class="small-upload close-delete"
                                  :pic-name-list.sync="scope.row.officialNameList"
                                  :max-size="scope.row.officialUrlList?scope.row.officialUrlList.length:0"
                                  @showImg="showImg"></pic-view>
                      </template>
                      <template v-else-if="col.key === 'product_picture'">
                        <pic-view :file-list="scope.row.productUrlList"
                                  upload-class="small-upload close-delete"
                                  :pic-name-list.sync="scope.row.productNameList"
                                  :max-size="scope.row.productUrlList?scope.row.productUrlList.length:0"
                                  @showImg="showImg"></pic-view>
                      </template>
                      <template v-else-if="col.key === 'main_fabric'">
                        <span>{{scope.row.main_fabric}}</span>
                        <pic-view :file-list="scope.row.bodyUrlList"
                                  upload-class="small-upload close-delete"
                                  :pic-name-list.sync="scope.row.bodyNameList"
                                  :max-size="scope.row.bodyUrlList?scope.row.bodyUrlList.length:0"
                                  @showImg="showImg"></pic-view>
                      </template>
                      <template v-else-if="col.key === 'bolster_fabric'">
                        <span>{{scope.row.bolster_fabric}}</span>
                        <pic-view :file-list="scope.row.pillowUrlList"
                                  upload-class="small-upload close-delete"
                                  :pic-name-list.sync="scope.row.pillowNameList"
                                  :max-size="scope.row.pillowUrlList?scope.row.pillowUrlList.length:0"
                                  @showImg="showImg"></pic-view>
                      </template>
                      <template v-else-if="col.key === 'wood_texture'">
                        <span>{{scope.row.wood_texture}}</span>
                        <pic-view :file-list="scope.row.woodenUrlList"
                                  upload-class="small-upload close-delete"
                                  :pic-name-list.sync="scope.row.woodenNameList"
                                  :max-size="scope.row.woodenUrlList?scope.row.woodenUrlList.length:0"
                                  @showImg="showImg"></pic-view>
                      </template>
                      <template v-else-if="col.key === 'other_texture'">
                        <span>{{scope.row.other_texture}}</span>
                        <pic-view :file-list="scope.row.otherUrlList"
                                  upload-class="small-upload  close-delete"
                                  :pic-name-list.sync="scope.row.otherNameList"
                                  :max-size="scope.row.otherUrlList?scope.row.otherUrlList.length:0"
                                  @showImg="showImg"></pic-view>
                      </template>
                      <template v-else-if="col.key === 'problem_picture'">
                        <pic-view :file-list="scope.row.problemUrlList"
                                  upload-class="small-upload close-delete"
                                  :pic-name-list.sync="scope.row.problemNameList"
                                  :max-size="scope.row.problemUrlList?scope.row.problemUrlList.length:0"
                                  @showImg="showImg"></pic-view>
                      </template>
                      <template v-else><span>{{scope.row[col.key]}}</span></template>
                    </template>
                  </el-table-column>
                </template>
                <el-table-column label="操作"
                                 align="center">
                  <template slot-scope="scope">
                    <template v-if="scope.row.status===2 && buttonAuthority.some(a => a==='judgeOrder')">
                      <el-button size="mini"
                                 type="primary"
                                 @click="judgeChildOrder(scope.row.id, scope.row.orderId, scope.row.status)">审核</el-button>
                    </template>
                    <template v-if="props.row.status === 4 && scope.row.status===4 && !scope.row.readyTime && buttonAuthority.some(a => a==='productReady')">
                      <el-button size="mini"
                                 type="primary"
                                 @click="productReady(scope.row.id, scope.row.orderId)">货好时间</el-button>
                    </template>
                    <template v-if="scope.row.status===11 && buttonAuthority.some(a => a==='expectArrived')">
                      <el-button size="mini"
                                 plain
                                 type="primary"
                                 @click="expectArrived(scope.row.id, scope.row.orderId)">预计到港</el-button>
                    </template>
                    <template v-if="scope.row.status===5 && buttonAuthority.some(a => a==='laidUp')">
                      <el-button size="mini"
                                 type="warning"
                                 @click="laidUp(scope.row.id, scope.row.orderId)">入库</el-button>
                    </template>
                    <template v-if="scope.row.status===9 && buttonAuthority.some(a => a==='firstSend')">
                      <el-button size="mini"
                                 type="primary"
                                 @click="firstSend(scope.row.id, scope.row.orderId)">配送时间</el-button>
                    </template>
                    <template v-if="scope.row.status===9 && buttonAuthority.some(a => a==='finish') && scope.row.distribution_time">
                      <el-button size="mini"
                                 type="success"
                                 @click="finish(scope.row.id, scope.row.orderId)">完成</el-button>
                    </template>
                  </template>
                </el-table-column>
              </el-table>
            </template>
          </el-table-column>
          <template v-for='(col) in orderHeader'>
            <el-table-column :show-overflow-tooltip="true"
                             :label="col.value"
                             :key="col.key">
              <template slot-scope="scope">
                <template v-if="col.key === 'contract_picture'">
                  <pic-view :file-list="scope.row.contractUrlList"
                            upload-class="short-upload close-delete"
                            :pic-name-list.sync="scope.row.contractNameList"
                            :max-size="scope.row.contractUrlList?scope.row.contractUrlList.length:0"
                            @showImg="showImg"></pic-view>
                </template>
                <template v-else-if="col.key === 'income_prove_picture'">
                  <pic-view :file-list="scope.row.incomeUrlList"
                            upload-class="short-upload close-delete"
                            :pic-name-list.sync="scope.row.incomeNameList"
                            :max-size="scope.row.incomeUrlList?scope.row.incomeUrlList.length:0"
                            @showImg="showImg"></pic-view>
                </template>
                <template v-else><span>{{scope.row[col.key]}}</span></template>
              </template>
            </el-table-column>
          </template>
          <el-table-column label="附件"
                           width="180"
                           align="center">
            <template slot-scope="scope">
              <el-row>
                <template v-if="scope.row.status > 5 && scope.row.status < 10">
                  <template v-if="buttonAuthority.some(a => a==='printDistribution')">
                    <el-button size="mini"
                               plain
                               type="primary"
                               @click="print(scope.row.id, 'distribution')">配送单</el-button>
                  </template>
                  <template v-if="buttonAuthority.some(a => a==='printShipment')">
                    <el-button size="mini"
                               plain
                               type="primary"
                               @click="print(scope.row.id, 'shipment')">出货单</el-button>
                  </template>
                </template>
                <template v-else>暂无可导出项</template>
              </el-row>
            </template>
          </el-table-column>
          <el-table-column label="操作"
                           width="180">
            <template slot-scope="scope">
              <el-row class="button-row">
                <template v-if="scope.row.status===6 && buttonAuthority.some(a => a==='upLastJudge')">
                  <el-button size="mini"
                             type="primary"
                             @click="lastJudgeOrder(scope.row.id)">提交售后审核</el-button>
                </template>
                <template v-if="scope.row.status===3 && buttonAuthority.some(a => a==='modifyUp')">
                  <el-button size="mini"
                             type="primary"
                             @click="submitOrder(scope.row.id)">提交审核</el-button>
                  <el-button size="mini"
                             type="warning"
                             @click="modifyOrder(scope.row.id)">修改</el-button>
                </template>
                <template v-if="scope.row.status==2 && scope.row.item.every(a => a.status === 4) && buttonAuthority.some(a => a==='judgeOrder')">
                  <el-button size="mini"
                             type="warning"
                             @click="judgeOrder(scope.row.id, scope.row.status)">审核</el-button>
                </template>
                <template v-if="scope.row.status===7 && buttonAuthority.some(a => a==='checkOrder')">
                  <el-button size="mini"
                             type="warning"
                             @click="checkOrder(scope.row.id, scope.row.status)">审查</el-button>
                </template>
              </el-row>
              <el-row class="button-row">
                <template v-if="scope.row.status===10 && buttonAuthority.some(a => a==='reVisit')">
                  <el-button size="mini"
                             type="primary"
                             v-if="!scope.row.report_time"
                             @click="reVisitTime(scope.row.id)">回访时间</el-button>
                  <el-button size="mini"
                             type="primary"
                             v-if="!scope.row.report_advice"
                             @click="reVisit(scope.row.id)">回访意见</el-button>
                </template>
              </el-row>
              <el-row class="button-row">
                <template v-if="buttonAuthority.some(a => a==='confirmFinCost')">
                  <el-button size="mini"
                             type="primary"
                             @click="confirmFinCost(scope.row.id)">确认尾款</el-button>
                </template>
                <el-button size="mini"
                           type="info"
                           @click="detail(scope.row.id)">详情</el-button>
              </el-row>
              <el-row class="button-row">
                <template v-if="buttonAuthority.some(a => a==='modifyOrder')">
                  <el-button size="mini"
                             type="danger"
                             @click="modifyOrderAll(scope.row.id)">修改订单</el-button>
                </template>
                <template v-if="buttonAuthority.some(a => a==='deleteOrder')">
                  <el-button size="mini"
                             type="danger"
                             @click="deleteOrder(scope.row.id)">删除</el-button>
                </template>
              </el-row>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <div class="table-foot">
      </div>
    </div>
    <view-page :current-page="currentPage"
               :total="total"
               @change="pageChange"></view-page>
    <el-dialog :title="confirmObj.title"
               :visible.sync="dialog">
      <template v-if="confirmObj.key == 'readyTime'">
        <el-form>
          <el-form-item label="货好时间"
                        label-width="120">
            <el-date-picker v-model="confirmObj.goodsFinishTime"
                            type="date"
                            format="yyyy-MM-dd"
                            value-format="yyyy-MM-dd"
                            placeholder="货好时间">
            </el-date-picker>
          </el-form-item>
        </el-form>
      </template>
      <template v-if="confirmObj.key == 'arrivalTime'">
        <span>厂家货物准备完成</span>
        <el-form>
          <el-form-item label="预计到港时间"
                        label-width="120">
            <el-date-picker v-model="confirmObj.arrivalTime"
                            type="date"
                            format="yyyy-MM-dd"
                            value-format="yyyy-MM-dd"
                            placeholder="预计到港时间">
            </el-date-picker>
          </el-form-item>
        </el-form>
      </template>
      <template v-if="confirmObj.key == 'finalCost'">
        <span>是否确认尾款已结清，并上传尾款凭证</span>
        <pic-view :file-list="confirmObj.finalCostUrlList"
                  upload-class="short-upload"
                  :pic-name-list.sync="confirmObj.finalCostNameList"
                  :max-size="5"
                  :upload-data="{ fileName: 'finalCost' }"
                  @showImg="showImg"></pic-view>
      </template>
      <template v-if="confirmObj.key == 'laidUpTime'">
        <el-form>
          <el-form-item label="入库时间"
                        label-width="120">
            <el-date-picker v-model="confirmObj.laidUpTime"
                            type="date"
                            format="yyyy-MM-dd"
                            value-format="yyyy-MM-dd"
                            placeholder="入库时间">
            </el-date-picker>
          </el-form-item>
        </el-form>
      </template>
      <template v-if="confirmObj.key == 'sendTime'">
        <el-form>
          <el-form-item label="配送时间"
                        label-width="120">
            <el-date-picker v-model="confirmObj.sendTime"
                            type="date"
                            format="yyyy-MM-dd"
                            value-format="yyyy-MM-dd"
                            placeholder="配送时间">
            </el-date-picker>
          </el-form-item>
        </el-form>
      </template>
      <template v-if="confirmObj.key == 'finishedTime'">
        <el-form>
          <el-form-item label="完成时间"
                        label-width="120">
            <el-date-picker v-model="confirmObj.finishedTime"
                            type="date"
                            format="yyyy-MM-dd"
                            value-format="yyyy-MM-dd"
                            placeholder="完成时间">
            </el-date-picker>
          </el-form-item>
        </el-form>
      </template>
      <template v-if="confirmObj.key == 'reportTime'">
        <el-form>
          <el-form-item label="回访时间"
                        label-width="120">
            <el-date-picker v-model="confirmObj.reportTime"
                            type="date"
                            format="yyyy-MM-dd"
                            value-format="yyyy-MM-dd"
                            placeholder="回访时间">
            </el-date-picker>
          </el-form-item>
        </el-form>
      </template>
      <template v-if="confirmObj.key == 'reportAdvice'">
        <el-input v-model="confirmObj.reportAdvice"
                  type="textarea"
                  rows="3"></el-input>
      </template>
      <template v-if="confirmObj.key == 'judge'">
        <span>是否提交审核</span>
      </template>
      <div slot="footer"
           class="dialog-footer">
        <el-button @click="dialog = false">取 消</el-button>
        <el-button type="primary"
                   @click="toModify">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<style>
.el-table .warning-row {
  background: #f9d490cf;
}
</style>

<script>
import { mapGetters } from 'vuex'
import { vListLength, validatenull } from '@/utils/validate'
import '@/style/common.scss'
import picView from '@/components/pic-viewer-up'
import vViewer from '@/components/v-viewer'
import { packageImgList } from '@/utils/imgPackage'
import viewPage from '@/components/pagination'
import { api } from '@/api'
import { HTTPSUCCESS, HTTPDATAFAIL, HTTPPARAMFAIL, HTTPUNKOWNFAIL } from '@/components/constant'

export default {
  data() {
    return {
      nowOpen: [],
      orderId: this.$route.query.orderId,
      roleId: null,
      userId: null,
      dateRange: [],
      finalCostStatus: null,
      customerPhone: null,
      customerName: null,
      orderStatus: this.$route.query.status || null,
      currentPage: 0,
      total: null,
      orderList: [],
      buttonAuthority: [],
      orderHeader: [],
      childOrderHeader: [],
      dialog: false,
      confirmObj: {
      }
    }
  },
  computed: {
    ...mapGetters([
      'roles', 'authority', 'user', 'orderOpenedRow'
    ])
  },
  activated() {
    this.setAuthority()
    this.getOrderList()
  },
  components: { picView, vViewer, viewPage },
  methods: {
    validatenull,
    vListLength,
    print(orderId, type) {
      let url
      if (type === 'shipment') url = api.PRINTING_SHIPMENT
      if (type === 'distribution') url = api.PRINTING_DISTRIBUTION
      this.$http.get(url, { id: orderId }).then(
        res => {
          if (res.error.code === HTTPSUCCESS) {
            self.location.href = res.result
          } else {
            this.$msg._message(res.error.message, 'success')
          }
        }
      )
    },
    statusColor({ row, rowIndex }) {
      if (row.status === 3 || row.status === 8) {
        return 'warning-row'
      }
      return ''
    },
    setAuthority() {
      let user = this.user
      if (typeof (user) === 'string') user = JSON.parse(user)
      this.buttonAuthority = this.authority.buttonAuthority
      this.orderHeader = this.authority.orderHeader
      this.childOrderHeader = this.authority.childOrderHeader
      this.roleId = user['roleId']
      this.userId = user['userId']
    },
    reset() {
      this.orderId = null
      this.customerName = null
      this.customerPhone = null
      this.finalCostStatus = null
      this.orderStatus = null
      this.dateRange = []
      this.getOrderList()
      this.$router.push({
        name: 'order'
      })
    },
    getOrderList() {
      const params = {
        minTime: this.dateRange[0],
        maxTime: this.dateRange[1],
        orderId: this.orderId,
        customerName: this.customerName,
        customerPhone: this.customerPhone,
        finalCostStatus: this.finalCostStatus,
        orderStatus: Number.parseInt(this.orderStatus),
        pageNum: this.currentPage,
        pageSize: 10
      }
      if (this.roleId === 2) params.salesmanId = this.userId
      this.$http.post(api.ORDER_LIST, params).then(
        res => {
          if (res.result.hasContent) {
            this.orderList = res.result.content
            this.orderList.forEach(e => {
              if (e.final_cost_picture) {
                const finalCostPictureList = packageImgList(e.final_cost_picture)
                e.finalCostNameList = finalCostPictureList[0]
                e.finalCostUrlList = finalCostPictureList[1]
              }
              if (e.contract_picture) {
                const contractList = packageImgList(e.contract_picture)
                e.contractNameList = contractList[0]
                e.contractUrlList = contractList[1]
              }
              if (e.income_prove_picture) {
                const incomeList = packageImgList(e.income_prove_picture)
                e.incomeNameList = incomeList[0]
                e.incomeUrlList = incomeList[1]
              }
              e.item.forEach(ele => {
                if (ele.official_picture) {
                  const officialList = packageImgList(ele.official_picture)
                  ele.officialNameList = officialList[0]
                  ele.officialUrlList = officialList[1]
                }
                if (ele.product_picture) {
                  const productList = packageImgList(ele.product_picture)
                  ele.productNameList = productList[0]
                  ele.productUrlList = productList[1]
                }
                if (ele.main_fabric_picture) {
                  const bodyList = packageImgList(ele.main_fabric_picture)
                  ele.bodyNameList = [ele.main_fabric_picture]
                  ele.bodyUrlList = bodyList[1]
                }
                if (ele.bolster_fabric_picture) {
                  const pillowList = packageImgList(ele.bolster_fabric_picture)
                  ele.pillowNameList = [ele.bolster_fabric_picture]
                  ele.pillowUrlList = pillowList[1]
                }
                if (ele.wood_texture_picture) {
                  const woodenList = packageImgList(ele.wood_texture_picture)
                  ele.woodenNameList = [ele.wood_texture_picture]
                  ele.woodenUrlList = woodenList[1]
                }
                if (ele.other_texture_picture) {
                  const otherList = packageImgList(ele.other_texture_picture)
                  ele.otherNameList = [ele.other_texture_picture]
                  ele.otherUrlList = otherList[1]
                }
                if (ele.problem_picture) {
                  const problemList = packageImgList(ele.problem_picture)
                  ele.problemNameList = problemList[0]
                  ele.problemUrlList = problemList[1]
                }
              })
            })
            this.currentPage = res.result.pageNumber
            this.total = res.result.totalElements
            const isOpen = Number.parseInt(this.orderOpenedRow)
            if (isOpen !== -1 && this.orderList.some(e => e.id === isOpen)) {
              this.nowOpen = [isOpen]
            }
            this.$store.dispatch('OpenRow', -1)
          } else {
            this.orderList = []
            this.currentPage = 0
            this.total = null
          }
        }
      )
    },
    judgeOrder(id, status) {
      this.$router.push({
        name: 'judgeOrder',
        params: { orderId: id, status: status }
      })
    },
    judgeChildOrder(childId, orderId, status) {
      this.$router.push({
        name: 'judgeChildOrder',
        params: { childId: childId, status: status }
      })
      this.$store.dispatch('OpenRow', orderId)
    },
    checkOrder(id, status) {
      this.$router.push({
        name: 'judgeOrder',
        params: { orderId: id, status: status }
      })
    },
    detail(id) {
      this.$router.push({
        name: 'orderDetail',
        params: { orderId: id }
      })
    },
    newOrder() {
      this.$router.push({
        name: 'newOrder'
      })
    },
    modifyOrder(id) {
      this.$router.push({
        name: 'modifyOrder',
        params: { orderId: id }
      })
    },
    modifyOrderAll(id) {
      this.$router.push({
        name: 'modifyOrderAll',
        params: { orderId: id }
      })
    },
    submitOrder(id) {
      this.confirmObj = {
        orderId: id,
        title: '注意',
        key: 'judge'
      }
      this.dialog = true
    },
    productReady(id, orderId) {
      this.confirmObj = {
        orderId: orderId,
        childOrderId: id,
        title: '货好时间',
        key: 'readyTime'
      }
      this.$store.dispatch('OpenRow', orderId)
      this.dialog = true
    },
    expectArrived(id, orderId) {
      this.confirmObj = {
        orderId: orderId,
        childOrderId: id,
        title: '预计到货',
        key: 'arrivalTime'
      }
      this.$store.dispatch('OpenRow', orderId)
      this.dialog = true
    },
    confirmFinCost(id) {
      const thisOrder = this.orderList.filter(e => e.id === id)
      this.confirmObj = {
        finalCostNameList: !validatenull(thisOrder[0].finalCostNameList) ? thisOrder[0].finalCostNameList : [],
        finalCostUrlList: !validatenull(thisOrder[0].finalCostUrlList) ? thisOrder[0].finalCostUrlList : [],
        orderId: id,
        title: '确认尾款',
        key: 'finalCost'
      }
      this.dialog = true
    },
    laidUp(id, orderId) {
      this.confirmObj = {
        orderId: orderId,
        childOrderId: id,
        title: '入库',
        key: 'laidUpTime'
      }
      this.$store.dispatch('OpenRow', orderId)
      this.dialog = true
    },
    firstSend(id, orderId) {
      this.confirmObj = {
        orderId: orderId,
        childOrderId: id,
        title: '优先配送',
        key: 'sendTime'
      }
      this.orderList.forEach(e => {
        if (e.id === orderId && e.item) {
          e.item.forEach(a => {
            if (a.id === id && !validatenull(a.distribution_time)) {
              this.$set(this.confirmObj, 'sendTime', new Date(a.distribution_time))
            }
          })
        }
      })
      this.$store.dispatch('OpenRow', orderId)
      this.dialog = true
    },
    finish(id, orderId) {
      this.confirmObj = {
        orderId: orderId,
        childOrderId: id,
        title: '完成',
        key: 'finishedTime'
      }
      this.$store.dispatch('OpenRow', orderId)
      this.dialog = true
    },
    reVisitTime(id) {
      this.confirmObj = {
        orderId: id,
        title: '设置回访时间',
        key: 'reportTime'
      }
      this.dialog = true
    },
    reVisit(id) {
      this.confirmObj = {
        orderId: id,
        title: '回访意见',
        key: 'reportAdvice'
      }
      this.dialog = true
    },
    deleteOrder(id) {
      this.confirmObj = {
        id: id,
        title: '确认删除？',
        key: 'deleteOrder'
      }
      this.dialog = true
    },
    lastJudgeOrder(id) {
      this.$http.get(api.ORDER_LASTJUDGE, { orderId: id }).then(
        res => {
          if (res.error.code === HTTPSUCCESS) {
            this.$msg._message('操作成功！', 'success')
            this.getOrderList()
          } else {
            this.$msg._message(res.error.message, 'success')
          }
        }
      )
    },
    toModify() {
      let url
      if (this.confirmObj.key === 'readyTime' || this.confirmObj.key === 'arrivalTime' || this.confirmObj.key === 'laidUpTime' || this.confirmObj.key === 'finalCost') {
        url = api.CHILD_ORDER_EDIT
      } else if (this.confirmObj.key === 'finishedTime' || this.confirmObj.key === 'reportTime' || this.confirmObj.key === 'reportAdvice' || this.confirmObj.key === 'sendTime') {
        url = api.CHILD_ORDER_SALE
      } else if (this.confirmObj.key === 'deleteOrder') {
        url = api.ORDER_DELETE
      } else {
        url = api.ORDER_APPROVE
      }
      if (this.confirmObj.key === 'finalCost') {
        this.confirmObj.finalCostStatus = 1
        this.confirmObj.finalCostPicture = this.confirmObj.finalCostNameList.join(',')
        delete this.confirmObj['finalCostUrlList']
        delete this.confirmObj['finalCostNameList']
      }
      if (this.confirmObj.key === 'judge') {
        delete this.confirmObj['key']
        delete this.confirmObj['title']
        this.$http.get(url, this.confirmObj).then(
          res => {
            if (res.error.code === HTTPSUCCESS) {
              this.dialog = false
              this.$msg._message('操作成功！', 'success')
              this.getOrderList()
            } else {
              this.$msg._message(res.error.message, 'success')
            }
          }
        )
      } else {
        delete this.confirmObj['key']
        delete this.confirmObj['title']
        this.$http.post(url, this.confirmObj).then(
          res => {
            if (res.error.code === HTTPSUCCESS) {
              this.dialog = false
              this.$msg._message('操作成功！', 'success')
              if (res.result && res.result.orderId) {
                this.confirmObj = {
                  orderId: res.result.orderId,
                  title: '设置回访时间',
                  key: 'reportTime'
                }
                this.dialog = true
              }
              this.getOrderList()
            } else {
              this.$msg._message(res.error.message, 'success')
            }
          }
        )
      }
    },
    pageChange(page) {
      this.currentPage = page - 1
      this.getOrderList()
    },
    showImg(url) {
      this.$refs.view.showImg(url)
    }
  }

}
</script>
